Fix: Sanitize parameter descriptions to prevent code generation errors#1
Merged
Merged
Conversation
## Problem Parameter descriptions from OpenAPI specifications were not being sanitized, causing TypeScript compilation errors in generated MCP servers when descriptions contained: - Newlines (line breaks) - Single quotes - HTML entities (<, >, `, ', etc.) This resulted in unterminated string literals in the generated code, breaking the build process for servers created from well-documented APIs like Azure OpenAI. ## Solution - Added `sanitizeDescription()` private method to centralize description sanitization logic - Method handles: - HTML entity decoding (<, >, ", ', `, &) - Newline removal and whitespace collapsing - Single quote escaping for JavaScript string safety - Updated all 8 locations where parameter descriptions are assigned to use the new sanitization method ## Impact - Fixes build failures for generated servers with complex API documentation - Ensures consistent description handling across all parsing methods (OpenAPI, Postman, plain text) - Prevents future issues with special characters in descriptions Fixes issue with generated server build failures due to unterminated string literals in parameter descriptions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Parameter descriptions from OpenAPI specifications were not being sanitized, causing TypeScript compilation errors in generated MCP servers when descriptions contained:
<,>,`,', etc.)This resulted in unterminated string literals in the generated code, breaking the build process for servers created from well-documented APIs like Azure OpenAI.
Example Error
Solution
sanitizeDescription()private method to centralize description sanitization logic<,>,",',`,&)Changes
src/generator/ApiParser.ts: AddedsanitizeDescription()method and updated all description assignmentsImpact
Testing
Related Issue
Fixes build failures when generating MCP servers from APIs with multi-line parameter descriptions (e.g., Azure OpenAI API).